package lily.phs.pregnance;

import lily.phs.object.FirstPrenatalVisit;
import lily.phs.object.HereTipa;
import lily.phs.object.PrenatalVisit;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;


import android.content.Context;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 第1次产前访视记录表（第2页，共2页）的界面和数据处理
 * @author heckassitant
 *
 */
public class FirstPrenatalVisitView_2 extends LinearLayout implements OnClickListener, OnFocusChangeListener{
	
	private MyPopupWindow mPopupWindow;
	private Context mContext;
	private int profileid=0;
	
	private EditText et_hemoglobin,et_wbc,et_blood_platelet,et_blood_other,et_pro,et_glu,et_urine_ketone,et_bld,et_urine_other,
	                 et_bs,et_serum_cpt,et_serum_ast,et_blood_protein,et_tbil,et_dbil,et_serum_creatinine,et_bun,
	                 et_vaginal_discharge_other,et_surface_antigen,et_surface_antibody,et_e_antigen,et_e_antibody,et_core_antibody,
	                 et_brightness_mode,et_overall_access_abnormal,et_healthguide_other,et_transfer_reason,et_transfer_hospital,
	                 et_next_visit_date,et_doctor;
	private RadioGroup rgBloodType,rgBloodRh,rgVaginaCleanness,rgSyphilisSeroTest,rgHivTest,rgOverallAccess,rgNeedTransfer;
	private RadioButton rb_blood_type_1,rb_blood_type_2,rb_blood_type_3,rb_blood_type_4,rb_blood_rh_1,rb_blood_rh_2,
	                    rb_vagina_cleanness_1,rb_vagina_cleanness_2,rb_vagina_cleanness_3,rb_vagina_cleanness_4,
	                    rb_syphilis_sero_test_1,rb_syphilis_sero_test_2,rb_hiv_test_1,rb_hiv_test_2,rb_overall_access_1,rb_overall_access_2,
	                    rb_need_transfer_1,rb_need_transfer_2;
	
	private CheckBox cb_vaginal_discharge_1,cb_vaginal_discharge_2,cb_vaginal_discharge_3,cb_vaginal_discharge_4,cb_healthguide_1,
	                 cb_healthguide_2,cb_healthguide_3,cb_healthguide_4,cb_healthguide_5,cb_healthguide_6;
	
//	private HereTipa ht;
	private FirstPrenatalVisit fp;
	private View child;

	public FirstPrenatalVisitView_2(Context context,int profileId) {
		super(context);
		// TODO Auto-generated constructor stub
		this.profileid = profileId;
		this.mContext = context;
		final LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		child = inflater.inflate(R.layout.tablepreg1_plus, null);
	}
	/**
	 * 控件与xml文件关联
	 */
	public void findViewsById() {
		// TODO Auto-generated method stub
		et_hemoglobin = (EditText)child.findViewById(R.id.first_hemoglobin);
		et_wbc = (EditText)child.findViewById(R.id.first_wbc);
		et_blood_platelet = (EditText)child.findViewById(R.id.first_blood_platelet);
		et_blood_other = (EditText)child.findViewById(R.id.first_blood_other);
		et_pro = (EditText)child.findViewById(R.id.first_pro);
		et_glu = (EditText)child.findViewById(R.id.first_glu);
		et_urine_ketone = (EditText)child.findViewById(R.id.first_urine_ketone);
		et_bld = (EditText)child.findViewById(R.id.first_bld);
		et_urine_other = (EditText)child.findViewById(R.id.first_urine_other);
        et_bs = (EditText)child.findViewById(R.id.first_bs);
        et_serum_cpt = (EditText)child.findViewById(R.id.first_serum_cpt);
        et_serum_ast = (EditText)child.findViewById(R.id.first_serum_ast);
        et_blood_protein = (EditText)child.findViewById(R.id.first_blood_protein);
        et_tbil = (EditText)child.findViewById(R.id.first_tbil);
        et_dbil = (EditText)child.findViewById(R.id.first_dbil);
        et_serum_creatinine = (EditText)child.findViewById(R.id.first_serum_creatinine);
        et_bun = (EditText)child.findViewById(R.id.first_bun);
        et_vaginal_discharge_other = (EditText)child.findViewById(R.id.first_vaginal_discharge_other);
        et_vaginal_discharge_other.setOnFocusChangeListener(this);
        et_vaginal_discharge_other.setOnClickListener(this);
        et_surface_antigen = (EditText)child.findViewById(R.id.first_surface_antigen);
        et_surface_antibody = (EditText)child.findViewById(R.id.first_surface_antibody);
        et_e_antigen = (EditText)child.findViewById(R.id.first_e_antigen);
        et_e_antibody = (EditText)child.findViewById(R.id.first_e_antibody);
        et_core_antibody = (EditText)child.findViewById(R.id.first_core_antibody);
        et_brightness_mode = (EditText)child.findViewById(R.id.first_brightness_mode);
        et_overall_access_abnormal = (EditText)child.findViewById(R.id.first_overall_access_abnormal);
        et_overall_access_abnormal.setOnFocusChangeListener(this);
        et_overall_access_abnormal.setOnClickListener(this);
        et_healthguide_other = (EditText)child.findViewById(R.id.first_healthguide_other);
        et_healthguide_other.setOnFocusChangeListener(this);
        et_healthguide_other.setOnClickListener(this);
        et_transfer_reason = (EditText)child.findViewById(R.id.first_transfer_reason);
        et_transfer_reason.setOnFocusChangeListener(this);
        et_transfer_reason.setOnClickListener(this);
        et_transfer_hospital = (EditText)child.findViewById(R.id.first_transfer_hospital);
        et_transfer_hospital.setOnFocusChangeListener(this);
        et_transfer_hospital.setOnClickListener(this);
        et_next_visit_date = (EditText)child.findViewById(R.id.first_next_visit_date);
        et_next_visit_date.setInputType(InputType.TYPE_NULL);
        et_next_visit_date.setOnClickListener(this);
        et_next_visit_date.setOnFocusChangeListener(this);
        et_doctor = (EditText)child.findViewById(R.id.first_doctor);
		rb_blood_type_1 = (RadioButton)child.findViewById(R.id.first_blood_type_1);
		rb_blood_type_2 = (RadioButton)child.findViewById(R.id.first_blood_type_2);
		rb_blood_type_3 = (RadioButton)child.findViewById(R.id.first_blood_type_3);
		rb_blood_type_4 = (RadioButton)child.findViewById(R.id.first_blood_type_4);
		rb_blood_rh_1 = (RadioButton)child.findViewById(R.id.first_blood_rh_1);
		rb_blood_rh_2 = (RadioButton)child.findViewById(R.id.first_blood_rh_2);
        rb_vagina_cleanness_1 = (RadioButton)child.findViewById(R.id.first_vagina_cleanness_1);
        rb_vagina_cleanness_2 = (RadioButton)child.findViewById(R.id.first_vagina_cleanness_2);
        rb_vagina_cleanness_3 = (RadioButton)child.findViewById(R.id.first_vagina_cleanness_3);
        rb_vagina_cleanness_4 = (RadioButton)child.findViewById(R.id.first_vagina_cleanness_4);
        rb_syphilis_sero_test_1 = (RadioButton)child.findViewById(R.id.first_syphilis_sero_test_1);
        rb_syphilis_sero_test_2 = (RadioButton)child.findViewById(R.id.first_syphilis_sero_test_2);
        rb_hiv_test_1 = (RadioButton)child.findViewById(R.id.first_hiv_test_1);
        rb_hiv_test_2 = (RadioButton)child.findViewById(R.id.first_hiv_test_2);
        rb_overall_access_1 = (RadioButton)child.findViewById(R.id.first_overall_access_1);
        rb_overall_access_2 = (RadioButton)child.findViewById(R.id.first_overall_access_2);
        rb_need_transfer_1 = (RadioButton)child.findViewById(R.id.first_need_transfer_1);
        rb_need_transfer_2 = (RadioButton)child.findViewById(R.id.first_need_transfer_2);
		cb_vaginal_discharge_1 = (CheckBox)child.findViewById(R.id.first_vaginal_discharge_1);
		cb_vaginal_discharge_2 = (CheckBox)child.findViewById(R.id.first_vaginal_discharge_2);
		cb_vaginal_discharge_3 = (CheckBox)child.findViewById(R.id.first_vaginal_discharge_3);
		cb_vaginal_discharge_4 = (CheckBox)child.findViewById(R.id.first_vaginal_discharge_4);
		cb_healthguide_1 = (CheckBox)child.findViewById(R.id.first_healthguide_1);
        cb_healthguide_2 = (CheckBox)child.findViewById(R.id.first_healthguide_2);
        cb_healthguide_3 = (CheckBox)child.findViewById(R.id.first_healthguide_3);
        cb_healthguide_4 = (CheckBox)child.findViewById(R.id.first_healthguide_4);
        cb_healthguide_5 = (CheckBox)child.findViewById(R.id.first_healthguide_5);
        cb_healthguide_6 = (CheckBox)child.findViewById(R.id.first_healthguide_6);
        rgBloodType = (RadioGroup)child.findViewById(R.id.RadioGroup06);
        rgBloodRh = (RadioGroup)child.findViewById(R.id.RadioGroup05);
        rgVaginaCleanness = (RadioGroup)child.findViewById(R.id.radioGroup1);
        rgSyphilisSeroTest = (RadioGroup)child.findViewById(R.id.RadioGroup01);
        rgHivTest = (RadioGroup)child.findViewById(R.id.RadioGroup02);
        rgOverallAccess = (RadioGroup)child.findViewById(R.id.RadioGroup03);
        rgNeedTransfer = (RadioGroup)child.findViewById(R.id.RadioGroup04);
	}
	
	/**
	 * 初始化views
	 */
	public void initViews() {
		// TODO Auto-generated method stub
		
		initialState();
		
		String temp="";
		int itemp=-1;
		float ftemp=-1f;
		
		ftemp = fp.getFipv_hemoglobin();
		if(ftemp!=-1f){
			et_hemoglobin.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_wbc();
		if(ftemp!=-1f){
			et_wbc.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_blood_platelet();
		if(ftemp!=-1f){
			et_blood_platelet.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_blood_other();
		if(ftemp!=-1f){
			et_blood_other.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_pro();
		if(ftemp!=-1f){
			et_pro.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_glu();
		if(ftemp!=-1f){
			et_glu.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_urine_ketone();
		if(ftemp!=-1f){
			et_urine_ketone.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_bld();
		if(ftemp!=-1f){
			et_bld.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_urine_other();
		if(ftemp!=-1f){
			et_urine_other.setText(String.valueOf(ftemp));
		}
		
		temp = fp.getFipv_blood_type();
		if(temp.equals("A型")){
			rgBloodType.check(0);
			rb_blood_type_1.setChecked(true);
		}else if(temp.equals("B型")){
			rgBloodType.check(1);
			rb_blood_type_2.setChecked(true);
		}else if(temp.equals("AB型")){
			rgBloodType.check(2);
			rb_blood_type_3.setChecked(true);
		}else if(temp.equals("O型")){
			rgBloodType.check(3);
			rb_blood_type_4.setChecked(true);
		}
		
		temp = fp.getFipv_blood_rh();
		if(temp.equals("阴性")){
			rgBloodRh.check(0);
			rb_blood_rh_1.setChecked(true);
		}else if(temp.equals("阳性")){
			rgBloodRh.check(1);
			rb_blood_rh_2.setChecked(true);
		}
		
		ftemp = fp.getFipv_bs();
		if(ftemp!=-1f){
			et_bs.setText(String.valueOf(ftemp));
		}
		
		ftemp = fp.getFipv_serum_cpt();
		if(ftemp!=-1f){
			et_serum_cpt.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_serum_ast();
		if(ftemp!=-1f){
			et_serum_ast.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_blood_protein();
		if(ftemp!=-1f){
			et_blood_protein.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_tbil();
		if(ftemp!=-1f){
			et_tbil.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_dbil();
		if(ftemp!=-1f){
			et_dbil.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_serum_creatinine();
		if(ftemp!=-1f){
			et_serum_creatinine.setText(String.valueOf(ftemp));
		}
		ftemp = fp.getFipv_bun();
		if(ftemp!=-1f){
			et_bun.setText(String.valueOf(ftemp));
		}
		
		temp = fp.getFipv_vaginal_discharge();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_vaginal_discharge_1.setChecked(true);
					break;
				case 2:
					cb_vaginal_discharge_2.setChecked(true);
					break;
				case 3:
					cb_vaginal_discharge_3.setChecked(true);
					break;
				case 4:{
					cb_vaginal_discharge_4.setChecked(true);
					temp = fp.getFipv_vaginal_other_discharge();
					et_vaginal_discharge_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = fp.getFipv_vagina_cleanness();
		switch(itemp){
		case 1:
			rgVaginaCleanness.check(0);
			rb_vagina_cleanness_1.setChecked(true);
			break;
		case 2:
			rgVaginaCleanness.check(1);
			rb_vagina_cleanness_2.setChecked(true);
			break;
		case 3:
			rgVaginaCleanness.check(2);
			rb_vagina_cleanness_3.setChecked(true);
			break;
		case 4:
			rgVaginaCleanness.check(3);
			rb_vagina_cleanness_4.setChecked(true);
			break;
		}
		
		temp = fp.getFipv_surface_antigen();
		et_surface_antigen.setText(temp);
		temp = fp.getFipv_surface_antibody();
		et_surface_antibody.setText(temp);
		temp = fp.getFipv_e_antigen();
		et_e_antigen.setText(temp);
		temp = fp.getFipv_e_antibody();
		et_e_antibody.setText(temp);
		temp = fp.getFipv_core_antibody();
		et_core_antibody.setText(temp);
		
		itemp = fp.getFipv_syphilis_sero_test();
		switch(itemp){
		case 1:
			rgSyphilisSeroTest.check(0);
			rb_syphilis_sero_test_1.setChecked(true);
			break;
		case 2:
			rgSyphilisSeroTest.check(1);
			rb_syphilis_sero_test_2.setChecked(true);
			break;
		}
		itemp = fp.getFipv_hiv_test();
		switch(itemp){
		case 1:
			rgHivTest.check(0);
			rb_hiv_test_1.setChecked(true);
			break;
		case 2:
			rgHivTest.check(1);
			rb_hiv_test_2.setChecked(true);
			break;
		}
		
		temp = fp.getFipv_brightness_mode();
		et_brightness_mode.setText(temp);
		
		itemp = fp.getFipv_overall_access();
		switch(itemp){
		case 1:
			rgOverallAccess.check(0);
			rb_overall_access_1.setChecked(true);
			break;
		case 2:{
			rgOverallAccess.check(1);
			rb_overall_access_2.setChecked(true);
			temp = fp.getFipv_overall_access_abnormal();
			et_overall_access_abnormal.setText(temp);
			break;
		}
		}
		
		temp = fp.getFipv_healthguide();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_healthguide_1.setChecked(true);
					break;
				case 2:
					cb_healthguide_2.setChecked(true);
					break;
				case 3:
					cb_healthguide_3.setChecked(true);
					break;
				case 4:
					cb_healthguide_4.setChecked(true);
					break;
				case 5:
					cb_healthguide_5.setChecked(true);
					break;
				case 6:{
					cb_healthguide_6.setChecked(true);
					temp = fp.getFipv_healthguide_other();
					et_healthguide_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = fp.getFipv_need_transfer();
		switch(itemp){
		case 1:
			rgNeedTransfer.check(0);
			rb_need_transfer_1.setChecked(true);
			break;
		case 2:
			rgNeedTransfer.check(1);
			rb_need_transfer_2.setChecked(true);
			break;
		}
		temp = fp.getFipv_transfer_reason();
		et_transfer_reason.setText(temp);
		temp = fp.getFipv_transfer_hospital();
		et_transfer_hospital.setText(temp);
		temp = fp.getFipv_next_visit_date();
		et_next_visit_date.setText(temp);
		temp = fp.getFipv_doctor();
		et_doctor.setText(temp);
		
	}
	/**
	 * 初始时状态：横线为空，所有选择项未选中
	 */
	private void initialState() {
		// TODO Auto-generated method stub
		et_hemoglobin.setText("");
		et_wbc.setText("");
		et_blood_platelet.setText("");
		et_blood_other.setText("");
		et_pro.setText("");
		et_glu.setText("");
		et_urine_ketone.setText("");
		et_bld.setText("");
		et_urine_other.setText("");
        et_bs.setText("");
        et_serum_cpt.setText("");
        et_serum_ast.setText("");
        et_blood_protein.setText("");
        et_tbil.setText("");
        et_dbil.setText("");
        et_serum_creatinine.setText("");
        et_bun.setText("");
        et_vaginal_discharge_other.setText("");
        et_surface_antigen.setText("");
        et_surface_antibody.setText("");
        et_e_antigen.setText("");
        et_e_antibody.setText("");
        et_core_antibody.setText("");
        et_brightness_mode.setText("");
        et_overall_access_abnormal.setText("");
        et_healthguide_other.setText("");
        et_transfer_reason.setText("");
        et_transfer_hospital.setText("");
        et_next_visit_date.setText("");
        et_doctor.setText("");

		rb_blood_type_1.setChecked(false);
		rb_blood_type_2.setChecked(false);
		rb_blood_type_3.setChecked(false);
		rb_blood_type_4.setChecked(false);
		rb_blood_rh_1.setChecked(false);
		rb_blood_rh_2.setChecked(false);
        rb_vagina_cleanness_1.setChecked(false);
        rb_vagina_cleanness_2.setChecked(false);
        rb_vagina_cleanness_3.setChecked(false);
        rb_vagina_cleanness_4.setChecked(false);
        rb_syphilis_sero_test_1.setChecked(false);
        rb_syphilis_sero_test_2.setChecked(false);
        rb_hiv_test_1.setChecked(false);
        rb_hiv_test_2.setChecked(false);
        rb_overall_access_1.setChecked(false);
        rb_overall_access_2.setChecked(false);
        rb_need_transfer_1.setChecked(false);
        rb_need_transfer_2.setChecked(false);

		cb_vaginal_discharge_1.setChecked(false);
		cb_vaginal_discharge_2.setChecked(false);
		cb_vaginal_discharge_3.setChecked(false);
		cb_vaginal_discharge_4.setChecked(false);
		cb_healthguide_1.setChecked(false);
        cb_healthguide_2.setChecked(false);
        cb_healthguide_3.setChecked(false);
        cb_healthguide_4.setChecked(false);
        cb_healthguide_5.setChecked(false);
        cb_healthguide_6.setChecked(false);
		
	}

	/**
	 * 从数据库中检出数据
	 */
	public void fetchData(){
		fp = new FirstPrenatalVisit(mContext);
		fp.selectFirstPrenatalVisit(this.profileid);
		
	}
	
	/**
	 * 将view添加到父view中
	 */
	public void setMyView(){
		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(child,lp);
	}
	
	/**
	 * 将整个界面作为一个view对象
	 * @return 整个界面view
	 */
	public View getMyView(){
		return this.child;
	}
	
	/**
	 * 保存views的值到数据库
	 */
	public void saveViews() {
		// TODO Auto-generated method stub
		String temp = "";
		StringBuffer sb=null;
		
		FirstPrenatalVisit fp = new FirstPrenatalVisit(mContext);
		fp.setFipv_id(this.profileid);
		fp.selectFirstPrenatalVisit(profileid);
		
		temp = et_hemoglobin.getText().toString();
		if(temp.length()>0){
			fp.setFipv_hemoglobin(Float.parseFloat(temp));
		}
		temp = et_wbc.getText().toString();
		if(temp.length()>0){
			fp.setFipv_wbc(Float.parseFloat(temp));
		}
		temp = et_blood_platelet.getText().toString();
		if(temp.length()>0){
			fp.setFipv_blood_platelet(Float.parseFloat(temp));
		}
		temp = et_blood_other.getText().toString();
		if(temp.length()>0){
			fp.setFipv_blood_other(Float.parseFloat(temp));
		}
		temp = et_pro.getText().toString();
		if(temp.length()>0){
			fp.setFipv_pro(Float.parseFloat(temp));
		}
		temp = et_glu.getText().toString();
		if(temp.length()>0){
			fp.setFipv_glu(Float.parseFloat(temp));
		}
		temp = et_urine_ketone.getText().toString();
		if(temp.length()>0){
			fp.setFipv_urine_ketone(Float.parseFloat(temp));
		}
		temp = et_bld.getText().toString();
		if(temp.length()>0){
			fp.setFipv_bld(Float.parseFloat(temp));
		}
		temp = et_urine_other.getText().toString();
		if(temp.length()>0){
			fp.setFipv_urine_other(Float.parseFloat(temp));
		}
		
		if(rb_blood_type_1.isChecked()==true){
			fp.setFipv_blood_type("A型");
		}else if(rb_blood_type_2.isChecked()==true){
			fp.setFipv_blood_type("B型");
		}else if(rb_blood_type_3.isChecked()==true){
			fp.setFipv_blood_type("AB型");
		}else if(rb_blood_type_4.isChecked()==true){
			fp.setFipv_blood_type("O型");
		}
		if(rb_blood_rh_1.isChecked()==true){
			fp.setFipv_blood_rh("阴性");
		}else if(rb_blood_rh_2.isChecked()==true){
			fp.setFipv_blood_rh("阳性");
		}
		
		temp = et_bs.getText().toString();
		if(temp.length()>0){
			fp.setFipv_bs(Float.parseFloat(temp));
		}
		temp = et_serum_cpt.getText().toString();
		if(temp.length()>0){
			fp.setFipv_serum_cpt(Float.parseFloat(temp));
		}
		temp = et_serum_ast.getText().toString();
		if(temp.length()>0){
			fp.setFipv_serum_ast(Float.parseFloat(temp));
		}
		temp = et_blood_protein.getText().toString();
		if(temp.length()>0){
			fp.setFipv_blood_protein(Float.parseFloat(temp));
		}
		temp = et_tbil.getText().toString();
		if(temp.length()>0){
			fp.setFipv_tbil(Float.parseFloat(temp));
		}
		temp = et_dbil.getText().toString();
		if(temp.length()>0){
			fp.setFipv_dbil(Float.parseFloat(temp));
		}
		temp = et_serum_creatinine.getText().toString();
		if(temp.length()>0){
			fp.setFipv_serum_creatinine(Float.parseFloat(temp));
		}
		temp = et_bun.getText().toString();
		if(temp.length()>0){
			fp.setFipv_bun(Float.parseFloat(temp));
		}
		
		sb = new StringBuffer();
		if(cb_vaginal_discharge_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_vaginal_discharge_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_vaginal_discharge_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_vaginal_discharge_4.isChecked()==true){
			sb.append("4,");
			temp = et_vaginal_discharge_other.getText().toString();
			fp.setFipv_vaginal_other_discharge(temp);
		}
		fp.setFipv_vaginal_discharge(sb.toString());
		
		if(rb_vagina_cleanness_1.isChecked()==true){
			fp.setFipv_vagina_cleanness(1);
		}else if(rb_vagina_cleanness_2.isChecked()==true){
			fp.setFipv_vagina_cleanness(2);
		}else if(rb_vagina_cleanness_3.isChecked()==true){
			fp.setFipv_vagina_cleanness(3);
		}else if(rb_vagina_cleanness_4.isChecked()==true){
			fp.setFipv_vagina_cleanness(4);
		}
		
		temp = et_surface_antigen.getText().toString();
		fp.setFipv_surface_antigen(temp);
		temp = et_surface_antibody.getText().toString();
		fp.setFipv_surface_antibody(temp);
		temp = et_e_antigen.getText().toString();
		fp.setFipv_e_antigen(temp);
		temp = et_e_antibody.getText().toString();
		fp.setFipv_e_antibody(temp);
		temp = et_core_antibody.getText().toString();
		fp.setFipv_core_antibody(temp);
		
		if(rb_syphilis_sero_test_1.isChecked()==true){
			fp.setFipv_syphilis_sero_test(1);
		}else if(rb_syphilis_sero_test_2.isChecked()==true){
			fp.setFipv_syphilis_sero_test(2);
		}
		if(rb_hiv_test_1.isChecked()==true){
			fp.setFipv_hiv_test(1);
		}else if(rb_hiv_test_2.isChecked()==true){
			fp.setFipv_hiv_test(2);
		}
		
		temp = et_brightness_mode.getText().toString();
		fp.setFipv_brightness_mode(temp);
		if(rb_overall_access_1.isChecked()==true){
			fp.setFipv_overall_access(1);
		}else if(rb_overall_access_2.isChecked()==true){
			fp.setFipv_overall_access(2);
			temp = et_overall_access_abnormal.getText().toString();
			fp.setFipv_overall_access_abnormal(temp);
		}
		
		sb = new StringBuffer();
		if(cb_healthguide_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_healthguide_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_healthguide_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_healthguide_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_healthguide_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_healthguide_6.isChecked()==true){
			sb.append("6,");
			temp = et_healthguide_other.getText().toString();
			fp.setFipv_healthguide_other(temp);
		}
		fp.setFipv_healthguide(sb.toString());
		
		if(rb_need_transfer_1.isChecked()==true){
			fp.setFipv_need_transfer(1);
		}else if(rb_need_transfer_2.isChecked()==true){
			fp.setFipv_need_transfer(2);
			temp = et_transfer_reason.getText().toString();
			fp.setFipv_transfer_reason(temp);
			temp = et_transfer_hospital.getText().toString();
			fp.setFipv_transfer_hospital(temp);
		}
		temp = et_next_visit_date.getText().toString();
		fp.setFipv_next_visit_date(temp);
		temp = et_doctor.getText().toString();
		fp.setFipv_doctor(temp);
		
		fp.updateFirstPrenatalVisit(this.profileid);
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==et_next_visit_date){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.first_next_visit_date), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_vaginal_discharge_other){
			cb_vaginal_discharge_4.setChecked(true);
		}
		else if(v==et_overall_access_abnormal){
			rb_overall_access_1.setChecked(false);
			rb_overall_access_2.setChecked(true);
		}
		else if(v==et_healthguide_other){
			cb_healthguide_6.setChecked(true);
		}
		else if((v==et_transfer_reason||v==et_transfer_hospital)){
			rb_need_transfer_1.setChecked(false);
			rb_need_transfer_2.setChecked(true);
		}
		
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(v==et_vaginal_discharge_other&&hasFocus){
			cb_vaginal_discharge_4.setChecked(true);
		}
		else if(v==et_overall_access_abnormal&&hasFocus){
			rb_overall_access_1.setChecked(false);
			rb_overall_access_2.setChecked(true);
		}
		else if(v==et_healthguide_other&&hasFocus){
			cb_healthguide_6.setChecked(true);
		}
		else if((v==et_transfer_reason||v==et_transfer_hospital)&&hasFocus){
			rb_need_transfer_1.setChecked(false);
			rb_need_transfer_2.setChecked(true);
		}
		else if(v==et_next_visit_date&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.first_next_visit_date  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
	}

}
